package timeutil

import (
	"log"
	"time"
)

// Trace 记录方法执行时间
func Trace(msg string) func() {
	start := time.Now()
	log.Printf("%s start:%s", msg, TimeFormat(start.Unix()))
	return func() {
		log.Printf("%s end:%s cost (%s)", msg, TimeFormat(time.Now().Unix()), time.Since(start))
	}

}

// TimeFormat 普通unix时间转换
func TimeFormat(ts int64) string {
	if ts <= 0 {
		ts = time.Now().Unix()
	}
	tm := time.Unix(ts, 0)
	return tm.Format("2006-01-02 15:04:05")
}
